<template>
    <rx-dialog style="height: 100%;" @handOk="onOk" @cancel="cancel">

        <a-form  layout="vertical" class="rx-a-form-vertical">
            <a-form-item :label="i18n('formReport.reportPrint','报表打印')">
                <rx-input-button
                    v-model="dialogVal"
                    @click="selectUreportView"
                    style='width: 300px;'
                >
                </rx-input-button>
            </a-form-item>
            <a-form-item :label="i18n('list.paramConfig','参数配置')">
                <a-table :dataSource="config.params" :pagination="false"
                         rowKey="idx_">
                    <a-table-column :title="i18n('formReport.reportSelParam','报表参数')" dataIndex="bindFieldLabel" width="150px">
                        <template slot-scope="text, record">
                            <a-form-item class="tableItems">
                                {{ record.bindFieldLabel }}
                            </a-form-item>
                        </template>
                    </a-table-column>
                    <a-table-column :title="i18n('formReport.listField','列表字段')" dataIndex="returnField" width="300px">
                        <template slot-scope="text, record">
                            <a-row v-if="record.valmode=='double'">
                                <a-col :span="12">
                                    <a-form-item
                                        :label="i18n('customDialog.text','文本')"
                                        :labelCol="{span:6}"
                                        :wrapperCol="{span:15}"
                                        class="tableItems">
                                        <a-select style="width: 100%;" :placeholder="i18n('customDialog.text','文本')"
                                                  v-model="record.returnLabel"
                                                  :options="headerFields"
                                                  :getPopupContainer="p=>p.parentNode" allowClear>
                                        </a-select>
                                    </a-form-item>
                                </a-col>
                                <a-col :span="12">
                                    <a-form-item
                                        :label="i18n('customDialog.value','值')"
                                        :labelCol="{span:6}"
                                        :wrapperCol="{span:15}"
                                        class="tableItems">
                                        <a-select style="width: 150px;" :placeholder="i18n('customDialog.value','值')"
                                                  v-model="record.returnValue"
                                                  :options="headerFields"
                                                  :getPopupContainer="p=>p.parentNode" allowClear>
                                        </a-select>
                                    </a-form-item>
                                </a-col>
                            </a-row>
                            <a-form-item v-else
                                         class="tableItems">
                                <a-select style="width: 150px;"
                                          v-model="record.returnValue"
                                          :defaultValue="record.returnValue"
                                          :options="headerFields"
                                          :getPopupContainer="p=>p.parentNode" allowClear>
                                </a-select>
                            </a-form-item>
                        </template>
                    </a-table-column>
                </a-table>
            </a-form-item>
        </a-form>
    </rx-dialog>

</template>

<script>
import {RxDialog, Util} from "@lowcode/jpaas-common-lib";
import FormBoListApi from "@/api/form/core/formBoList";
import FormUreportList from "@/views/modules/form/core/FormUreportList";
import UreportListDialog from "@/views/modules/form/core/UreportListDialog";

export default {
    name: "FormListOpenUreportDialog",
    props: {
        layerid: {type: String},
        lydata: {type: Object},
        destroy: Function,
        //列表主键
        pkId: {type: String},
        //配置信息
        customConfig: {
            type: Object
        },
    },
    data() {
        return {
            boEntityShow: false,
            dialogVal: "",
            config: {
                alias: "",//alias
                name: "",//名称
                params:[],
                callBack:"",
                //窗口大小
                isMax:"YES",
                height:600,
                width:800
            },
            headerFields:[]
        }
    },
    created() {
        this.init();
    },
    methods: {
        i18n(name,text,key){
            return this.$ti18(name,text,"formBoList",key);
        },
        init(){
            this.reloadColumns();
            this.config=this.customConfig;
            this.dialogVal = JSON.stringify({text: this.config.name, value: this.config.name});
        },
        onOk() {
            Util.closeWindow(this, "ok", this.config);
        },
        cancel() {
            Util.closeWindow(this, "cancel");
        },
        reloadColumns() {
            let self_ = this;
            FormBoListApi.reloadColumns(self_.pkId).then(res => {
                self_.headerFields = res.data.map(function (item) {
                    item.value = item.field;
                    item.label=item.header;
                    return item
                });
                self_.$forceUpdate();
            });
        },
        selectUreportView(){
            var self = this;
            var config = {
                curVm: this,
                "data": {
                    "allowEdit": false
                },
                component: UreportListDialog,
                title: this.i18n('formReport.reportPrint','报表打印'),
                widthHeight: ['800px', '600px']
            };
            Util.open(config, function (action, data) {
                if (action != 'ok') return;
                var obj=data[0];
                self.dialogVal = JSON.stringify({text: obj.name, value: obj.alias});
                //self.config.alias=obj.alias;
                self.config.name=obj.name;
                if(obj.ureportFileQueryParameterList){
                    //var params=JSON.parse(data.params);
                    var params=obj.ureportFileQueryParameterList
                    self.config.params=[];

                    for (let i = 0; i < params.length; i++) {
                        self.config.params.push({
                            bindFieldLabel:params[i].name,
                            returnLabel:"",
                            returnValue:""
                        })
                    }
                }else {
                    self.config.params=[];
                }
                self.customConfig=self.config
            });
        }
    },

}
</script>

<style scoped>

</style>
